﻿using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Standard;
using Workflow.Application;
using Workflow.Application.Dto;
using Workflow.Application.Dto.Input;
using Workflow.Application.Dto.Output;
using Workflow.Domain.Model;
using WorkflowCore.Interface;
using Yitter.IdGenerator;

namespace Workflow.Host.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class WorkflowController : ControllerBase
    {
        private readonly IWorkflowService service;

        public WorkflowController(IWorkflowService service)
        {
            this.service = service;
        }
        /// <summary>
        /// 添加流程定义接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("AddDefinition")]
       public  ApiResult<int> AddDefinition(DefinitionInput input) 
        {
            return service.AddDefinition(input);
        }

        /// <summary>
        /// 发布申请接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("StartAudit")]
        public async Task<ApiResult<int>> StartAudit(StartAuditInput input)
        {
            return await service.StartAudit(input);
        }
        /// <summary>
        /// 显示流程定义接口
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAll")]
        public ApiResult<List<DefinitionModel>> GetAll() 
        {
            return service.GetAll();
        }
        /// <summary>
        /// 审批接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("Audit")]
        public async Task<ApiResult<int>> Audit(AuditInput input)
        {
            return await service.Audit(input);
        }
        /// <summary>
        /// 显示流程实例接口
        /// </summary>
        /// <param name="shuju"></param>
        /// <param name="yema"></param>
        /// <param name="name"></param>
        /// <param name="rolename"></param>
        /// <returns></returns>
        [HttpGet("GetInstance")]
        public ApiPaging<InstanceOutput> GetInstance(int shuju, int yema, string name, string rolename)
        {
            return service.GetInstance(shuju, yema, name, rolename);
        }
        /// <summary>
        /// 我的待审批接口
        /// </summary>
        /// <param name="auditusername"></param>
        /// <returns></returns>
        [HttpGet("GetAudit")]
        public ApiResult<List<AuditModel>> GetAudit(string auditusername)
        {
            return service.GetAudit(auditusername);
        }

    }
}
